from django.shortcuts import render

# Create your views here.

from rest_framework import viewsets
from rest_framework.permissions import IsAuthenticated

from environments.models import Environment
from environments.serializers import EnvironmentSerializer


class EnvironmentViewSet(viewsets.ModelViewSet):
    queryset = Environment.objects.all().filter(is_deleted=False)
    serializer_class = EnvironmentSerializer
    permission_classes = [IsAuthenticated]
    filterset_fields = ['project']  # noqa
    ordering = ['-create_time']  # 默认排序方式

    def perform_destroy(self, instance):
        instance.is_deleted = True
        instance.save()
